package cn.iocoder.lw.module.core.dal.mysql.workorder;

import cn.iocoder.lw.framework.common.pojo.PageResult;
import cn.iocoder.lw.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.lw.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.lw.module.core.dal.dataobject.workorder.CoreWorkOrderDO;
import cn.iocoder.lw.module.core.controller.admin.workorder.vo.workorder.CoreWorkOrderPageReqVO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 工单 Mapper
 *
 * @author Lw源码
 */
@Mapper
public interface CoreWorkOrderMapper extends BaseMapperX<CoreWorkOrderDO> {

    default PageResult<CoreWorkOrderDO> selectPage(CoreWorkOrderPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CoreWorkOrderDO>()
                .likeIfPresent(CoreWorkOrderDO::getOrderNo, reqVO.getOrderNo())
                .eqIfPresent(CoreWorkOrderDO::getProjectId, reqVO.getProjectId())
                .eqIfPresent(CoreWorkOrderDO::getHouseId, reqVO.getHouseId())
                .eqIfPresent(CoreWorkOrderDO::getDeviceId, reqVO.getDeviceId())
                .eqIfPresent(CoreWorkOrderDO::getStatus, reqVO.getStatus())
                .eqIfPresent(CoreWorkOrderDO::getInitiatorId, reqVO.getInitiatorId())
                .eqIfPresent(CoreWorkOrderDO::getAssigneeId, reqVO.getAssigneeId())
                .betweenIfPresent(CoreWorkOrderDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CoreWorkOrderDO::getId));
    }

    default List<CoreWorkOrderDO> selectListByProjectId(Long projectId) {
        return selectList(new LambdaQueryWrapperX<CoreWorkOrderDO>()
                .eq(CoreWorkOrderDO::getProjectId, projectId)
                .orderByDesc(CoreWorkOrderDO::getCreateTime));
    }

    default List<CoreWorkOrderDO> selectListByHouseId(Long houseId) {
        return selectList(new LambdaQueryWrapperX<CoreWorkOrderDO>()
                .eq(CoreWorkOrderDO::getHouseId, houseId)
                .orderByDesc(CoreWorkOrderDO::getCreateTime));
    }

    default List<CoreWorkOrderDO> selectListByDeviceId(Long deviceId) {
        return selectList(new LambdaQueryWrapperX<CoreWorkOrderDO>()
                .eq(CoreWorkOrderDO::getDeviceId, deviceId)
                .orderByDesc(CoreWorkOrderDO::getCreateTime));
    }

    default List<CoreWorkOrderDO> selectListByInitiatorId(Long initiatorId) {
        return selectList(new LambdaQueryWrapperX<CoreWorkOrderDO>()
                .eq(CoreWorkOrderDO::getInitiatorId, initiatorId)
                .orderByDesc(CoreWorkOrderDO::getCreateTime));
    }

    default List<CoreWorkOrderDO> selectListByAssigneeId(Long assigneeId) {
        return selectList(new LambdaQueryWrapperX<CoreWorkOrderDO>()
                .eq(CoreWorkOrderDO::getAssigneeId, assigneeId)
                .orderByDesc(CoreWorkOrderDO::getCreateTime));
    }

    default List<CoreWorkOrderDO> selectListByStatus(Integer status) {
        return selectList(new LambdaQueryWrapperX<CoreWorkOrderDO>()
                .eq(CoreWorkOrderDO::getStatus, status)
                .orderByDesc(CoreWorkOrderDO::getCreateTime));
    }

}